import {get,post} from '../../utils/request'
import qs from 'qs'
const state={
  //用来保存查询出来的栏目信息
  comments:[],
  total:0
}

const actions={
  //查询所有评论信息
  findAllComment(context,list){
    for (var propName in list) { 
      if (list[propName] === null || list[propName] === undefined || list[propName]==="") {
        delete list[propName];
      }
    }
    //异步操作
    get('/comment/pageQuery',list).then(res=>{
      let response=res.data.list
      context.commit('setComment',response)
      let total=res.data.total
      context.commit('setTotal',total)
    })
  },
  //审核评论
  check(context,params){
    let response=get('/comment/check',params)
    return response
  },
  //删除评论
  delete(context,id){
    let response=get('/comment/deleteById',id)
    return response
  },
  //批量删除
  deletes(context,ids){
    let response=post('/comment/batchDelete',ids)
    return response
  }
}
const mutations={
  //修改state中的值
  setComment(state,response){
    state.comments=response
  },
  setTotal(state,total){
    state.total=total
  }
}

export default{
  namespaced:true,
  state,
  actions,
  mutations
}